package com.siwei.mes.service.experiment.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.experiment.ItemorderExtend;
import com.siwei.mes.mapper.ItemorderExtendMapper;
import com.siwei.mes.service.experiment.ItemorderExtendService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 品控小票扩展表(ItemorderExtend)表服务实现类
 *
 * @author linzi
 * @since 2024-11-15 22:33:26
 */
@Service
public class ItemorderExtendServiceImpl implements ItemorderExtendService {
    @Resource
    private ItemorderExtendMapper itemorderExtendMapper;

    @Override
    public Long create(ItemorderExtend entity) {
        itemorderExtendMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(ItemorderExtend entity) {
        ItemorderExtend itemorderExtend = itemorderExtendMapper.selectByPrimaryKey(entity.getId());
        assertTrue(itemorderExtend == null, "品控小票扩展表信息不存在");
        itemorderExtendMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        ItemorderExtend itemorderExtend = itemorderExtendMapper.selectByPrimaryKey(id);
        assertTrue(itemorderExtend == null, "品控小票扩展表信息不存在");
        itemorderExtendMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<ItemorderExtend> getPage(PageQuery<ItemorderExtend, ItemorderExtend> query) {
        ItemorderExtend searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> itemorderExtendMapper.getList(searchParam));
    }

    @Override
    public ItemorderExtend loadById(Long id) {
        return itemorderExtendMapper.loadById(id);
    }

    @Override
    public List<ItemorderExtend> getAll(ItemorderExtend entity) {
        return itemorderExtendMapper.getList(entity);
    }
}
